Page({
  data: {
    interests: [
      { label: '甜口', value: 'sweet', checked: false },
      { label: '咸口', value: 'salty', checked: false },
      { label: '酸口', value: 'sour', checked: false },
      { label: '辣口', value: 'spicy', checked: false }
    ]
  },

  // 切换兴趣项的选中状态
  toggleInterest: function(e) {
    const index = e.currentTarget.dataset.index; // 获取当前点击项的索引
    let interests = this.data.interests;
    interests[index].checked = !interests[index].checked; // 切换选中状态
    this.setData({ interests: interests }); // 更新数据
  },

  // 显示已选择的兴趣项
  showSelection: function() {
    const selectedInterests = this.data.interests
      .filter(item => item.checked) // 过滤出被选中的兴趣项
      .map(item => item.label); // 将被选中的兴趣项标签映射到新数组
    wx.showToast({
      title: '你选择了：' + selectedInterests.join(', '), // 将选择的兴趣项以字符串形式展示
      icon: 'none',
      duration: 2000
    });
  }
});